package com.ly.common.servlet;

import com.ly.common.util.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 文件树
 * http://127.0.0.1/工程名/file/tree?path=WEB路径&file=*.html
 */
@WebServlet("/file/*")
public class FileTreeServlet extends BaseServlet {

    protected Object tree(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path = request.getParameter("path");
        String[] file = request.getParameterValues("file");
        if (path == null) {
            path = "/";
        }
        if (file == null || file.length == 0) {
            file = new String[]{"*.html"};
        }
        return IOUtils.fileTree(getServletContext().getRealPath(path), file);
    }
}
